﻿function Rectangle(position, size) {
    var rect = svg.append("rect")
            .attr("rx", "7.5")
            .attr("ry", "7.5")
            .attr("fill", "transparent")
            .attr("stroke", "black")
            .attr("stroke-width", "1")
            .attr("cursor", "move");

    BaseNode.apply(this, [rect, position, size]);

    this.onUpdateLayout = function () {
        rect.attr("x", this.getActualPosition().x)
            .attr("y", this.getActualPosition().y)
            .attr("width", this.getSize().w)
            .attr("height", this.getSize().h);
        if (this.logFlag) {
            worker.postMessage("Create a container:  x:" + this._position.x + ", y:" + this._position.x);
        }
        this.logFlag = false;
    };

    this.hitTest = function (pos) {
        var actualPosition = this.getActualPosition();
        if (pos.x > actualPosition.x
            && pos.y > actualPosition.y
            && pos.x < actualPosition.x + this.getSize().w
            && pos.y < actualPosition.y + this.getSize().h) {
            return new HitResult(true, actualPosition.x - pos.x, actualPosition.y - pos.y);
        }
        return new HitResult(false, 0, 0);
    }

    this.getCenterPos = function () { }
}